home *** CD-ROM | disk | FTP | other *** search
- /*
- * Binding abstract class
- *
- * a key - value binding pair.
- *
- * Copyright © John Wainwright 1988
- *
- * SuperClasses :
- *
- * Instance Vars :
- * key
- * value
- * Class Vars :
- *
- * Methods :
- * new k v - creates a Binding
- * isKey k - is this the key of the binding by == ?
- * isKeyEqual k - is this the key of the binding by equal
- * set v - set the value part
- * get - get the value part
- *
- * Class Methods :
- *
- */
-
- #include "oic.h"
- #include "generics.h"
-
- class Binding; /* the Binding class */
-
- struct Binding_i /* Binding instance structure */
- {
- object key; /* key */
- object value; /* value */
- };
- typedef struct Binding_i Binding_i;
-
- /* -------------------- Binding Instance methods ------------------- */
-
- method object
- _new(self, b, ba) /* initialise a new binding */
- object self;
- register Binding_i *b;
- register struct { object k, v; } *ba;
- {
- b->key = ba->k;
- b->value = ba->v;
-
- return self;
- }
-
-
- method int
- _isKey(self, b, keyp) /* is 'key' the binding key */
- object self;
- register Binding_i *b;
- register object *keyp;
- {
- return (b->key == *keyp);
- }
-
- method int
- _isKeyEqual(self, b, keyp) /* is 'key' the binding key by 'equal' */
- object self;
- register Binding_i *b;
- register object *keyp;
- {
- return (int)equal(b->key, *keyp);
- }
-
- method object
- _valueOf(self, b) /* get value part */
- object self;
- register Binding_i *b;
- {
- return b->value;
- }
-
- method object
- _keyOf(self, b) /* get key part */
- object self;
- register Binding_i *b;
- {
- return b->key;
- }
-
- method
- _set(self, b, valp) /* set value part */
- object self;
- register Binding_i *b;
- register object *valp;
- {
- b->value = *valp;
- }
-
- /* ------------------- Init the Binding class ---------------------- */
-
- InitBindingClass()
- {
- Binding = NewClass(sizeof(Binding_i), 0, "Binding", END);
- AddMethods(Binding,
- newGeneric, _new,
- isKeyGeneric, _isKey,
- isKeyEqualGeneric, _isKeyEqual,
- valueOfGeneric, _valueOf,
- keyOfGeneric, _keyOf,
- getGeneric, _valueOf,
- setGeneric, _set,
- END);
- }
-
-